<?php

namespace App\Http\Middleware;

use App\Exceptions\Fail;
use App\Http\Controllers\Admin\User;
use App\Http\Enums\HttpResCode;
use Closure;
use Illuminate\Http\Request;

class AdminAuthenticate
{
    /**
     * @throws Fail
     */
    public function handle(Request $request, Closure $next)
    {
        if (!User::validateToken($request->header('Authorize-Token'))) {
            throw new Fail('用户失效，请重新登录', HttpResCode::AuthFail);
        }
        return $next($request);
    }
}
